<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="box-card">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" class="input-with-select" v-model="queryOrders.query" clearable @clear="getOrdersList">
            <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <el-table :data="ordersList" style="width: 100%" border stripe>
         <el-table-column type="index" label="#"></el-table-column>
         <el-table-column prop="order_number" label="订单编号" width="900"></el-table-column>
         <el-table-column prop="order_price" label="商订单价格"></el-table-column>
         <el-table-column prop="" label="是否付款">
           <template slot-scope="scope">
             <el-tag type="danger" v-if="scope.row.pay_status === '0'">未付款</el-tag>
             <el-tag type="success" v-else>已付款</el-tag>
           </template>
         </el-table-column>
         <el-table-column label="是否发货">
           <template slot-scope="scope">
             <div v-if="scope.row.is_send === '否'">未发货</div>
             <div v-else>已发货</div>
           </template>
         </el-table-column>
         <el-table-column label="下单时间">
           <template slot-scope="scope">
             {{scope.row.update_time | dateFormat}}
           </template>
         </el-table-column>
         <el-table-column label="操作">
           <template slot-scope="scope">
             <el-button type="primary" plain size="mini" icon="el-icon-edit" title="修改订单地址"  @click="changeMap"></el-button>
             <el-button type="warning" plain size="mini" icon="el-icon-location" title="查看物流信息" @click="changeLog(scope.row.order_id)"></el-button>
           </template>
         </el-table-column>
       </el-table>
       <el-pagination
         @size-change="handleSizeChange"
         @current-change="handleCurrentChange"
         :current-page="queryOrders.pagenum"
         :page-sizes="[4, 6, 8, 10]"
         :page-size="queryOrders.pagesize"
         layout="total, sizes, prev, pager, next, jumper"
         :total="total"
         background>
       </el-pagination>
    </el-card>

    <!-- 物流信息 -->
    <el-dialog title="物流信息" :visible.sync="logDialogVisible" width="50%">
      <el-steps direction="vertical" :active="0">
        <el-step v-for="(item, index) in logData" :key="index" :title="item.ftime" :description="item.context"></el-step>
      </el-steps>
    </el-dialog>

    <!-- 选择地区 -->
    <el-dialog
      title="选择地区" :visible.sync="mapDialogVisible" width="50%">
      <el-form ref="mapFormRef" :model="mapForm" label-width="80px">
          <el-form-item label="省市区/县">
            <el-cascader v-model="mapForm.addressValue" :options="city"></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址">
            <el-input v-model="mapForm.address"></el-input>
          </el-form-item>
        </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="mapDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="mapDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from '../assets/citydata'
export default {
  data () {
    return {
      queryOrders: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      ordersList: [],
      logDialogVisible: false,
      logData: [],
      mapDialogVisible: false,
      mapForm: {
        addressValue: []
      },
      city: cityData
    }
  },

  created () {
    this.getOrdersList()
  },

  methods: {
    async getOrdersList () {
      const { data: res } = await this.$axios.get('orders', {
        params: this.queryOrders
      })
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.ordersList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange (el) {
      this.queryOrders.pagesize = el
      this.getOrdersList()
    },
    handleCurrentChange (el) {
      this.queryOrders.pagenum = el
      this.getOrdersList()
    },
    async changeLog (id) {
      this.logDialogVisible = true
      const { data: res } = await this.$axios.get('/kuaidi/1106975712662')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.logData = res.data
    },
    changeMap () {
      this.mapDialogVisible = true
    }
  }
}
</script>

<style scoped lang='less'>
  .el-pagination {
    margin-top: 15px;
  }
</style>
